package cn.minhx.domain.trade.service.settlement.factor;

import cn.minhx.domain.trade.moedel.entity.GroupBuyTeamEntity;
import cn.minhx.domain.trade.moedel.entity.MarketPayOrderEntity;
import cn.minhx.domain.trade.moedel.entity.TradeSettlementRuleCommandEntity;
import cn.minhx.domain.trade.moedel.entity.TradeSettlementRuleFilterBackEntity;
import cn.minhx.domain.trade.service.settlement.filter.EndRuleFilter;
import cn.minhx.domain.trade.service.settlement.filter.OutTradeNoRuleFilter;
import cn.minhx.domain.trade.service.settlement.filter.SCRuleFilter;
import cn.minhx.domain.trade.service.settlement.filter.SettableRuleFilter;
import cn.minhx.types.design.link.multi.LinkArmory;
import cn.minhx.types.design.link.multi.chain.BusinessLinkedList;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * 交易结算规则过滤工厂
 *
 * @author min
 */
@Slf4j
@Service
public class TradeSettlementRuleFilterFactory {

	@Bean("tradeSettlementRuleFilter")
	public BusinessLinkedList<TradeSettlementRuleCommandEntity, DynamicContext, TradeSettlementRuleFilterBackEntity> tradeSettlementRuleFilter(
			SCRuleFilter scRuleFilter, OutTradeNoRuleFilter outTradeNoRuleFilter, SettableRuleFilter settableRuleFilter,
			EndRuleFilter endRuleFilter) {

		// 组装链
		LinkArmory<TradeSettlementRuleCommandEntity, DynamicContext, TradeSettlementRuleFilterBackEntity> linkArmory = new LinkArmory<>(
				"交易结算规则过滤链", scRuleFilter, outTradeNoRuleFilter, settableRuleFilter, endRuleFilter);

		// 链对象
		return linkArmory.getLogicLink();
	}

	@Data
	@Builder
	@AllArgsConstructor
	@NoArgsConstructor
	public static class DynamicContext {
		// 订单营销实体对象
		private MarketPayOrderEntity marketPayOrderEntity;
		// 拼团组队实体对象
		private GroupBuyTeamEntity groupBuyTeamEntity;
	}
}
